package top.wardyan.common.util;

import java.util.function.Function;
import java.util.function.Predicate;

import cn.hutool.system.oshi.OshiUtil;

/**
 * 硬件相关工具
 * @author feng
 * 2021-09-14
 */
public class HardwareUtil {
	
	/**
	 * 获取CPU序列号
	 * @return
	 */
	public static String getProcessorID() {
		String rs = "";
		String cpumodel = OshiUtil.getCpuInfo().getCpuModel();
		var opt = cpumodel.lines().filter(new Predicate<>() {
			@Override
			public boolean test(String t) {
				return t.startsWith("ProcessorID:");
			}
		}).map(new Function<String, String>(){
			@Override
			public String apply(String t) {
				return t.substring(14);
			}
		}).findAny();
		if(opt != null && opt.isPresent()) {
			rs = opt.get();
		}
		return rs;
	}
	
	
	
	public static void main(String[] args) {
		// System.out.println(getProcessorID());
		System.out.println(String.format("CPU序列号:%s", getProcessorID()));
	}

}
